home *** CD-ROM | disk | FTP | other *** search
- Path: news2.noc.netcom.net!news
- From: Sean Palmer <sean@delta.com>
- Newsgroups: comp.lang.c++
- Subject: buffered streambuf in BC++4.52
- Date: Mon, 18 Mar 1996 22:36:32 -0500
- Organization: deltaComm Development, Inc.
- Message-ID: <314E2BC0.F3A@delta.com>
- NNTP-Posting-Host: landspeeder.delta.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Hi, I can't seem to get a buffered version of a streambuf to work in
- Borland C++ 4.52. Their docs are kinda skimpy, assuming you know all
- about iostreams already. If you can make this sample work or can email
- me a small working sample, thanks!
-
- Here's my non-working try:
-
- //.h file
- #include <iostream.h>
-
- struct debugstrbuf : streambuf {
- debugstrbuf();
- virtual int overflow(int c=EOF);
- virtual int doallocate();
- virtual int sync();
- protected:
- char buf[258];
- };
-
- //.cpp file
- static debugstrbuf globaldebugbuf;
-
- debugstrbuf::debugstrbuf() {
- cerr = &globaldebugbuf;
- clog = &globaldebugbuf;
- cout = &globaldebugbuf;
- allocate();
- }
-
- int debugstrbuf::overflow(int c) {
- if (c==EOF) c=0;
- *pptr()=(char)c;
- if (c) pptr()[1]=0;
- OutputDebugString(pbase());
- doallocate();
- return 0;
- }
- int debugstrbuf::doallocate() {
- enum { sz=sizeof(buf)-2 };
- setbuf(buf,sz);
- setp(buf,&buf[sz]);
- return sz;
- }
- int debugstrbuf::sync() { return 1; } //have tried 0
-
- In any case, subsequent attempts to do:
-
- cerr << "something" << endl;
-
- don't seem to do anything, but occasionally will overflow and cause some
- severe kind of lockup.
-
- I think I could handle it if I knew what the functions like setp and
- setbuf did, and how the various data members of streambuf were being
- manipulated by the iostream, but that's all hidden away and assumed that
- you know it already... So I'm just guessing.
-
- Thanks! Please reply via e-mail..
-